package com.gtm.controller;

import com.gtm.model.Translation;
import com.gtm.repository.TranslationRepository;
import com.gtm.repository.UserRepository;
import com.gtm.service.TranslationService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.xml.crypto.dsig.TransformService;
import java.io.IOException;
import java.text.ParseException;

@RestController
@RequestMapping("/translation")
public class TranslationController {
    @Autowired
    TranslationRepository tlr;

    @Autowired
    TranslationService tls;

    @Autowired
    UserRepository usr;

    @ApiOperation(value="uploadTranslation", notes="上传文献翻译",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "summary",value = "概要",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "transFile",value = "文件",dataType = "MultipartFile",paramType = "query")
    } )
    @RequestMapping("/uploadTranslation/{sid}")
    public Translation uploadTranslation(@PathVariable String sid,@RequestParam("summary")String summary,
                               @RequestParam("transFile")MultipartFile reviewFile) throws ParseException, IOException {
        return tls.uploadTranslation(sid,summary,reviewFile);
    }

    @ApiOperation(value="passTranslation", notes="通过翻译",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/passTranslation/{rid}")
    public Translation passTranslation(@PathVariable String rid,@RequestParam("comment") String comment){
        return tls.passTranslation(rid,comment);
    }

    @ApiOperation(value="depassTranslation", notes="撤销通过",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/depassTranslation/{rid}")
    public Translation depassTraslation(@PathVariable String rid,@RequestParam("comment") String comment){
        return tls.depassTranslation(rid,comment);
    }

    @ApiOperation(value="listBySid", notes="通过学生查找翻译",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/listBySid/{sid}")
    public Translation listBySid(@PathVariable String sid){
        return tlr.findByStuId(sid);
    }

    @ApiOperation(value="findById", notes="通过id查找",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/findById/{rid}")
    public Translation findById(@PathVariable String rid){
        return tlr.findOne(rid);
    }
}
